package cn.echoedu.specifics;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import cn.echoedu.daoconstants.TableName;
import cn.echoedu.entity.RequestMessage;
import cn.echoedu.entity.User;
import cn.echoedu.util.L;


public class SpecRequestMessage extends BaseSpec{
    private final String T="SpecRequestMessage-------->";
	@Override
	public <T> PreparedStatement getPreparedInsert(Connection con,
			TableName tableName, T currentPojo) throws SQLException {
		// TODO Auto-generated method stub
		L.gpi(T);
		RequestMessage requestmessage=(RequestMessage)currentPojo;
		String sql="insert into requestmessage values(?,?,?,?,?,?)";
		L.p(T+sql);
		PreparedStatement ps=con.prepareStatement(sql);
		ps.setInt(1,requestmessage.getRequestmessageid());
		ps.setString(2,requestmessage.getUser().getUsernumber());
		ps.setString(3,requestmessage.getMime());
		ps.setString(4,requestmessage.getMname());
		ps.setString(5,requestmessage.getIp());
		ps.setString(6,"");
		return ps;
	}

	@Override
	public <T> PreparedStatement getPreparedInsertRunning(Connection con,
			TableName tableName, T currentPojo) throws SQLException {
		// TODO Auto-generated method stub
		L.gpir(T);
		RequestMessage requestmessage=(RequestMessage)currentPojo;
		String sql="insert into requestmessage(usernumber,mime,name,ip,token,os," +
				"browser) values(?,?,?,?,?,?,?)";
		L.p(T+sql);
		PreparedStatement ps=con.prepareStatement(sql);
        ps.setString(1,requestmessage.getUser().getUsernumber());
		ps.setString(2,requestmessage.getMime());
		ps.setString(3,requestmessage.getMname());
		ps.setString(4,requestmessage.getIp());
		ps.setString(5,requestmessage.getToken());
		ps.setString(6,requestmessage.getOs());
		ps.setString(7,requestmessage.getBrowser());
		return ps;
	}

	@Override
	public Object getPojo(ResultSet rs) throws SQLException {
		// TODO Auto-generated method stub
		L.gp(T);
		RequestMessage requestmessage=new RequestMessage();
		requestmessage.setRequestmessageid(rs.getInt(1));
		User user=new User();
		user.setUsernumber(rs.getString(2));
		requestmessage.setUser(user);
		requestmessage.setMime(rs.getString(3));
		requestmessage.setMname(rs.getString(4));
		requestmessage.setIp(rs.getString(5));
		requestmessage.setToken(rs.getString(6));
		requestmessage.setOs(rs.getString(7));
		requestmessage.setBrowser(rs.getString(8));
		return requestmessage;
	}

	@Override
	public <T> PreparedStatement getPreparedUpdate(Connection con,
			TableName tableName, T oldPojo, T currentPojo) throws SQLException {
		// TODO Auto-generated method stub
		L.gpu(T);
		RequestMessage newrequestmessage=(RequestMessage)currentPojo;
		RequestMessage oldrequestmessage=(RequestMessage)oldPojo;
		String sql="update requestmessage set usernumber=?,mime=?,name=?,ip=?,token=?," +
				"os=?,browser=? where requestmessageid=?";
		L.p(T+sql);
		PreparedStatement ps=con.prepareStatement(sql);
		ps.setString(1,newrequestmessage.getUser().getUsernumber());
		ps.setString(2,newrequestmessage.getMime());
		ps.setString(3,newrequestmessage.getMname());
		ps.setString(4,newrequestmessage.getIp());
		ps.setString(5,newrequestmessage.getToken());
		ps.setString(6,newrequestmessage.getOs());
		ps.setString(7,newrequestmessage.getBrowser());
		ps.setInt(8,oldrequestmessage.getRequestmessageid());
		return ps;
	}

	@Override
	public Object getLeftJoinPojo(ResultSet rs) throws SQLException {
		// TODO Auto-generated method stub
		L.gljp(T);
		RequestMessage requestmessage = new RequestMessage();
		requestmessage.setRequestmessageid(rs.getInt("requestmessage.requestmessageid"));
		User user=new User();
		user.setUsernumber(rs.getString("user.usernumber"));
		 
		user.setRole(rs.getInt("user.role"));
		requestmessage.setUser(user);
		requestmessage.setMime(rs.getString("requestmessage.mime"));
		requestmessage.setMname(rs.getString("requestmessage.name"));
		requestmessage.setIp(rs.getString("requestmessage.ip"));
		requestmessage.setToken(rs.getString("requestmessage.token"));
		requestmessage.setOs(rs.getString("requestmessage.os"));
		requestmessage.setBrowser(rs.getString("requestmessage.browser"));
		 return requestmessage;
	}

	@Override
	public Object getPojoBySql(ResultSet rs) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public <T> String getPreparedInsertGetPrimaryKeySql(Connection con,
			TableName tableName, T currentPojo) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public <T> PreparedStatement getPreparedListInsert(Connection con,
			TableName tableName, T currentPojo) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public <T> PreparedStatement getPreparedListInsertRunning(Connection con,
			TableName tableName, T currentPojo) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

}
